package com.apes.scm.advanceOrder.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 功能：预售计划行数据
 *
 * @author HuJianLin
 * @create 2018-12-11 19:06
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = AdvanceSalePlanItem.CONST_TABLE_NAME)
public class AdvanceSalePlanItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "advance_sale_plan_item";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "预售计划单行")
    @Comment("行号")
    private long id;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("公司")
    private PartyRole company; //公司

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "advance_sale_plan_id", referencedColumnName = "id")
    @Comment("计划单号")
    private AdvanceSalePlan advanceSalePlan;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product; //商品

    @Column(name = "sales_control_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("数量")
    private double salesControlQty = 0; //数量(正数表示可预售数量，负数表示预留库存数量）

}
